<template>
  <div class="detail-log-con">
    <!-- <div class="table"> -->
    <!-- <div class="thead">
        <div class="tr">
          <div class="td">收/支</div>
          <div class="td">余额</div>
          <div class="td">时间</div>
        </div>
    </div>-->
    <div class="tbody" v-show="detailLog.length>0">
      <van-list
        v-model="loading"
        :finished="finished"
        :error.sync="error"
        error-text="请求失败，点击重新加载"
        finished-text=""
        @load="onLoad"
      >
        <div class="supplier_widthdraw_detail" v-for="(item,index) in detailLog" :key="index">
          <p>
            <span style="padding-left:1px;">&nbsp;订&nbsp;单&nbsp;号：</span>
            {{item.order_no}}
          </p>
          <p>
            <span>分账金额：</span>
            ¥{{item.amount}}
          </p>
          <p>
            <span>分账状态：</span>
            <span v-if="item.status == 0" class="gray">待分账</span>
            <span v-else-if="item.status == 1" class="yellow">已分账</span>
            <span v-else class="green">已取消</span>
          </p>
          <p v-if="item.status == 1">
            <span>分账时间：</span>
            {{item.sharing_time}}
          </p>
        </div>
      </van-list>
    </div>
    <div v-show="!detailLog.length && finished">
      <no-data :noData="noData"></no-data>
    </div>
    <!-- </div> -->
  </div>
</template>

<script>
import noData from '@/components/noData/index'
// import noDataImg from '@img/user/no_tx_log.png'
import Vue from 'vue'
// import { Grid, GridItem } from 'vant'
// Vue.use(Grid).use(GridItem)
import { getSharingList } from '@/api/user/gys/gysApi'

export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  created() {
    this.init()
  },
  data() {
    return {
      noData: {
        // img: noDataImg,
        text: '暂无分账明细'
      },
      page: 1,
      detailLog: [],
      error: false,
      loading: false,
      finished: false,
      isload: false
    }
  },
  props: {
    listPage: {
      type: Number,
      default: 0
    }
  },
  watch: {
    'listPage': {
      handler(val) {
        if (val == 1) {
          this.page = 1
          this.isload = false
          this.finished = false
          this.onLoad()
        }
      },
      deep: true
    }
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)

      this.onLoad()
    },
    onLoad() {
      const params = {
        // act_type: false,
        p: this.page
      }
      if (this.isload && this.page == 1){
        this.finished = true
        return
      }
      if (this.finished) {
        return
      }
      getSharingList(params)
        .then(res => {
          this.loading = false
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.$emit('changeListPage', 0)
            const resData = res.data
            this.isload = true
            if (this.page == 1) {
              this.detailLog = resData.data
            } else {
              this.detailLog.push(...resData.data)
            }
            if (resData.data.length < 10) {
              this.finished = true
            } else {
              this.page++
            }
          } else {
            this.$Error(res.msg)
          }
        })
        .catch(() => {
          this.error = true
        })
      // const data = { p: this.p }
      // getLetter(data)
      //   .then(res => {
      //     this.loading = false
      //     this.$loadingWrap.close()
      //     if (res.status == 1) {
      //       this.lists.push(...res.data)
      //       this.p = this.p + 1
      //     } else {
      //       this.finished = true
      //     }
      //   })
      //   .catch(() => {
      //     this.error = true
      //   })
    }
  }
})
</script>

<style lang="scss">
.detail-log-con {
  .supplier_widthdraw_detail {
    position: relative;
    z-index: 11;
    border-bottom: 2px solid #dcdcdc;
    padding: 20px;
    font-size: 28px;
    margin: 0 20px;
    p {
      line-height: 60px;
      width: 100%;
      color: #999;
      font-size: 26px;
      word-wrap: break-word;
      word-break: break-all;
      span {
        color: #ff8c10;
        font-size: 28px;
        margin-right: 16px;
        &.gray {
          color: #999;
        }
        &.yellow {
          color: #ff8c10;
        }
        &.green {
          color: #21e900;
        }
      }
    }
  }
  // margin: 0 20px;
  // text-align: center;
  // .tr {
  //   display: -webkit-box;
  //   display: -webkit-flex;
  //   display: flex;
  //   -webkit-flex-wrap: wrap;
  //   flex-wrap: wrap;
  //   .td {
  //     flex-basis: 33.3333%;
  //     flex-basis: 1;
  //     &:nth-child(1) {
  //       flex: 1;
  //     }
  //     &:nth-child(2) {
  //       flex: 1;
  //     }
  //     &:nth-child(3) {
  //       flex: 2;
  //     }
  //     &.no-data {
  //       color: #666;
  //     }
  //   }
  // }
  // .thead {
  //   font-weight: 500;
  //   background: #f4f4f4;
  //   .td {
  //     padding: 20px 0;
  //     color: #000;
  //   }
  // }
  // .tbody {
  //   .td {
  //     padding: 30px 0;
  //     &:nth-child(1) {
  //       color: #ff7200;
  //     }
  //     &:nth-child(2) {
  //       color: #333;
  //     }
  //     &:nth-child(3) {
  //       color: #666;
  //     }
  //   }
  // }
}
</style>
